package recycle.controller;

import recycle.pojo.Productcategory;
import recycle.service.ProductcategoryService;
import recycle.utils.Page;
import recycle.vo.ProductcategoryParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述：商品分类表 控制器
* @author 孙冉
* @date 2019/07/22
*/
@RestController
@RequestMapping("/productcategory")
public class ProductcategoryController{
	@Resource
	private ProductcategoryService productcategoryService;
 	
 	@RequestMapping("/findById.json")
    public Productcategory findById(Integer categoryId){
        Productcategory result = null;
        try {
            result = productcategoryService.findById(categoryId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：获取所有的Productcategory对象
     */
    @RequestMapping("/findAll.json")
    public List<Productcategory> findAll(){
        List<Productcategory> result = null;
        try {
            result = productcategoryService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Productcategory对象
     */
    @RequestMapping("/save.json")
    public Map save(Productcategory productcategory){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存商品分类表失败");
        try {
            if(productcategoryService.save(productcategory)>0){
                result.put("flag",true);
                result.put("msg","保存商品分类表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除商品分类表对象
     * @param categoryId
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer categoryId){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存商品分类表失败");
        try {
            if(productcategoryService.delete(categoryId)>0){
                result.put("flag",true);
                result.put("msg","保存商品分类表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新商品分类表对象
     */
    @RequestMapping("/update.json")
    public Map update(Productcategory productcategory){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新商品分类表失败");
        try {
            if( productcategoryService.update(productcategory)>0){
                result.put("flag",true);
                result.put("msg","更新商品分类表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Productcategory> query(ProductcategoryParam param){
        List<Productcategory> result = null;
        try {
            result = productcategoryService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(ProductcategoryParam param){
        Page result = null;
        try {
            result = productcategoryService.queryByPage(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/queryAllMobileProduct.json")
    public List<Productcategory> selectMobileProduct(){
        return productcategoryService.selectMobileProduct();
    }

    @RequestMapping("/queryAllComputerProduct.json")
    public List<Productcategory> selectComputerProduct(){
        return productcategoryService.selectComputerProduct();
    }

    @RequestMapping("/queryAllPadProduct.json")
    public List<Productcategory> selectPadProduct(){
        return productcategoryService.selectPadProduct();
    }
 }
